﻿#region File and License Information
/*
<File>
	<License>
		Copyright © 2009 - 2017, Daniel Vaughan. All rights reserved.
		This file is part of Calcium (http://calciumsdk.net), 
		which is released under the MIT License.
		See file /Documentation/License.txt for details.
	</License>
	<CreationDate>$CreationDate$</CreationDate>
</File>
*/
#endregion

using System;

namespace Outcoder
{
	public static class ComparableExtensions
	{
		public static T Clamp<T>(this T value, T minimum, T maximum) where T : IComparable<T>
		{
			if (value.CompareTo(minimum) < 0)
			{
				return minimum;
			}

			if (value.CompareTo(maximum) > 0)
			{
				return maximum;
			}

			return value;
		}
	}
}
